<?php
class User_Controller extends Base_Controller
{
	public function login()
	{
		user::login();
		url::redirect(request::referrer());
	}

	public function logout()
	{
		user::logout();
		url::redirect();
	}

	public function register()
	{
		$this->template->title = '注册';
		$form = $form_errors = array(
			'username'			=>	'',
			'email'				=>	'',
			'link'				=>	'',
			'password'			=>	'',
			'password_confirm'	=>	'',
		);
		$this->template->content = View::factory('user_register');
		$this->template->content->bind('form',$form)->bind('form_errors',$form_errors);
		if($_POST)
		{
			$data = $this->input->post();
			User_Validation::register($data);
			if($data->validate())
			{
				$form = $data->as_array();
				user::register($form);
				user::login();
				url::redirect();
			}
			else
			{
				$form_errors = arr::overwrite($form_errors,$data->errors('user_error.register'));
			}
			$form = $data->as_array();
		}
	}
}
